import 'dart:async';

import 'package:flutter/material.dart';

class ListenerManager<T> {
  final List<void Function(T)> _items = [];

  void listener(void Function(T) val) {
    _items.add(val);
  }

  /// 添加监听
  void add(T params) {
    for (var item in _items) {
      item(params);
    }
  }

  /// 移除监听
  void remove(void Function(T) val) {
    _items.remove(val);
  }

  /// 移除所有监听
  void removeAll() {
    _items.clear();
  }
}

class Dispose {
  final List<VoidCallback> _items = [];

  void add(VoidCallback fn) {
    _items.add(fn);
  }

  void execute() {
    for (var item in _items) {
      item();
    }
  }
}
